<?
class AAttachModel extends Model{
  /*
  *根据记录的类型和id返回该记录相关的附件
  */
  public function getByOid($oid,$type='article'){
    if(empty($oid))
	 return NULL;
	$list=$this->where("type={$type} and related_id={$oid}")->select();  
	return $list
  }
  
  /*
  *根据记录的类型和id删除该记录相关的附件
  */
  public function DelByOid($oid,$type='article'){
    if(empty($id))
	 return false;
	
	$list=$this->where("type={$type} and related_id={$oid}")->select();
	foreach($list as $li){
	  if($this->where("id={$li['id']}")->delete()){
	    @unlink("F:/www/main/".$li['file_path']);
	  }
	 }
	//return $list
  }
  
}
?>